package org.ipower.examsystem.dao.impl;

import java.util.List;
import org.ipower.examsystem.dao.ItemAnswerDao;
import org.ipower.examsystem.domain.ItemAnswer;
import org.ipower.examsystem.service.Answer;
import org.ipower.examsystem.service.Answers;

/**
 * 题目正确答案数据访问实现类。
 * @author young
 */
public class ItemAnswerDaoImpl extends ModuleGenericDaoImpl<ItemAnswer> implements  ItemAnswerDao{
    /**
     * 加载正确答案集合。
     * @param topicsID 题干ID。
     * @return 答案集合。
     * */
    @Override
    public Answers loadAnswers(String topicsID) {
        Answers answers = new Answers();
        if(topicsID != null && !topicsID.isEmpty()){
            List<ItemAnswer> list = this.loadAll("TopicsID", topicsID);
            if(list != null && list.size() > 0){
                for(ItemAnswer ia : list){
                   Answer answer = new Answer();
                   answer.setContent(ia.getContent());
                   answer.setImgUri(ia.getImgUri());
                   answer.setOptionID(ia.getOptionID());
                   answers.add(answer);
                }
            }
        }
        return answers;
    }

    @Override
    public void delete(String topicsID) {
        if(topicsID != null && !topicsID.isEmpty()){
            this.delete("TopicsID", topicsID);
        }
    }
}